import { defineStore } from 'pinia'
import {
  reqBookingScheduleData,
  reqFindDocScheduleListData,
  reqGetDoctorSheduleById,
  reqHospitalDepartmentData,
  reqHospitalResgiterData
} from '@/service/modules/hospital'

import type {
  IBookingScheduleData,
  IDoctorShedule,
  IFindScheduleListArr,
  IHospitalDepartmentArr,
  IHospitalRegisterData
} from '@/service/modules/hospital/type'
import { mapToMenu } from '@/utils/mapRouteToMenu'

interface IState {
  hospitalMenu: any[]
  registerData: IHospitalRegisterData
  departmentData: IHospitalDepartmentArr
  bookingSheduleData: IBookingScheduleData
  findScheduleList: IFindScheduleListArr
  doctorInfo: IDoctorShedule
}
export const useHospitalStore = defineStore('hospital', {
  state: (): IState => ({
    hospitalMenu: [],
    registerData: {},
    departmentData: [],
    bookingSheduleData: {
      bookingScheduleList: []
    },
    findScheduleList: [],
    doctorInfo: {} as IDoctorShedule
  }),
  actions: {
    // menuList
    fetchHospitalMenu() {
      this.hospitalMenu = mapToMenu('hospital')
      // 菜单路由
    },
    // register
    async fetchHospitalResgiterAction(hoscode: string) {
      const res = await reqHospitalResgiterData(hoscode)
      if (res.code == 200) {
        this.registerData = res.data
      }
    },
    // 科室
    async fetchHospitalDepartmentAction(hoscode: string) {
      const res = await reqHospitalDepartmentData(hoscode)
      if (res.code == 200) {
        this.departmentData = res.data
      }
    },
    //获取可预约排班数据
    async fetchHospitalWorkScheduleAction(
      page: number,
      limit: number,
      hoscode: string,
      depcode: string
    ) {
      const res = await reqBookingScheduleData(page, limit, hoscode, depcode)
      if (res.code == 200) {
        this.bookingSheduleData = res.data
      }
    },
    //
    async fetchFindScheduleListAction(config) {
      // const { hoscode, depcode, workDate } = config
      const res = await reqFindDocScheduleListData(config)
      if (res.code == 200) {
        this.findScheduleList = res.data
      }
    },
    async fetchGetDoctorSheduleInfoByIdAction(scheduleId: string) {
      const res = await reqGetDoctorSheduleById(scheduleId)
      if (res.code == 200) {
        this.doctorInfo = res.data
      }
    }
  }
})
